package com.cicc.beergamevirtualsimulationsystem.common.webSocket.handler.impl;

import com.cicc.beergamevirtualsimulationsystem.common.webSocket.config.WebSocketMessageSender;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.handler.JsonMessageHandler;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.message.Impl.StartJsonWebSocketMessage;
import com.cicc.beergamevirtualsimulationsystem.common.webSocket.message.WebSocketMessageTypeEnum;
import com.cicc.beergamevirtualsimulationsystem.entity.RoomInfoManager;
import com.cicc.beergamevirtualsimulationsystem.model.roleBinding.RoleBindingReq;
import com.cicc.beergamevirtualsimulationsystem.service.RoomService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.List;
import java.util.Set;

@Component
public class StartJsonMessageHandler implements JsonMessageHandler<StartJsonWebSocketMessage> {



    @Override
    public void handle(WebSocketSession session, StartJsonWebSocketMessage message) {
        Object roomId = session.getAttributes().get("roomId");
        StartJsonWebSocketMessage startJsonWebSocketMessage = new StartJsonWebSocketMessage("游戏开始");
        StartJsonWebSocketMessage startJsonWebSocketMessage2 = new StartJsonWebSocketMessage("游戏开始,你未选择角色");
        //广播对应房间所有用户游戏开始

        Set<String> selectedPlayerId = RoomInfoManager.getSelectedPlayerId(roomId.toString());
        WebSocketMessageSender.sendMessageToSelectedUser(roomId.toString(), startJsonWebSocketMessage,startJsonWebSocketMessage2,selectedPlayerId);
        //开始倒计时
        RoomInfoManager.startCountdown(roomId.toString());

        

    }

    @Override
    public String type() {
        return WebSocketMessageTypeEnum.GAME_START.getValue();
    }

    @Override
    public Class<StartJsonWebSocketMessage> getMessageClass() {
        return StartJsonWebSocketMessage.class;
    }
}
